<template>
	<div class="orderpage">
		<van-nav-bar title="确认订单">
			  <template #left>
			    <van-icon name="arrow-left" size="18" color="black" @click="backproduct"/>
			  </template>
			  <!-- <template #right>
			    <van-icon name="share-o" size="18" color="black"/>
			  </template> -->
		</van-nav-bar>
		<van-cell :title="shopname" icon="shop-o" :to="{ name: 'shopindex' }"/>
        <van-card num="1" price="2.00" :desc="item.description" :title="item.title" v-for="(item,index) in list" :key="index+'-only'">
        	<template #thumb>
        		<van-image width="100" height="90" :src="item.cover" />
        	</template>
        	<template #price>
        		<span style="color:#aaa">￥{{item.price}}</span>
        	</template>
			 <template #footer>
			    <span>需付款：</span><span style="color:red;font-size:15px">{{item.price}}</span>
			  </template>
        </van-card>
		<div class="mt-10" style="height:5px;background:#eee" />
		<!-- <van-cell title="优惠券/码" value="无可用" style="font-size: 12px;"/> -->
		<xjcoupon :info_id="item.columnid" @click="couponShow(index)" :ref="'coupon'+index" v-for="(item,index) in list" :key="index" :i="index" :more="true"></xjcoupon>
		<div style="height:5px;background:#eee" />
		<!-- <van-cell title="留言" value="选填,建议和商家沟通后再填写" style="font-size: 12px;"/> -->
		<div style="position:absolute;bottom:0;height:30px;background:#eee;"></div>
		<div class="fixorder">
		 <span class="ml-10" style="font-size: 14px;">合计：</span>
		 <span style="color:red;font-size:12px">￥</span>
		 <span style="color:red;font-size: 19px;">{{pricearr[0]}}</span>
		 <span style="color:red;font-size: 14px;">{{pricearr[1]}}</span>
		 <van-button type="warning" class="fr" style="border-radius: 15px;height: 30px;margin-top:10px;margin-right: 10px;" @click="submitOrder">提交订单</van-button>
		</div>
	</div>
</template>

<script>
import xjcoupon from '@/components/frontshop/xjcoupon.vue';
	export default {
		components: {
         xjcoupon
        },
		data() {
			return {
				pricearr:[],
				id:'',
				item:'',
				randcode:'',
                list:'',
                allprice:0,
                strlist:'',
				shopname: localStorage.getItem('shopname')?localStorage.getItem('shopname'):'', //店铺名
				jian_pricearr:[],
				ucp_idarr:[]
			}
		},
		methods:{
			//添加支付订单
			async submitOrder(){
				//let ordernumber=order_number();
				let res=await this.$frontaxios.post(this.$front.addMoreOrder,{couponlist:JSON.stringify(this.ucp_idarr),strlist:this.strlist,randcode:this.randcode});
				if(res.code==1){
				 this.$router.push({name:'paymore',query:{ordernumber:res.data.ordernumber,randcode:this.randcode,allprice:this.allprice}});//创建新订单成功
				 }else if(res.code==2){
					 this.$notify({type:'success',message:"你已经购买此商品，无需重复购买"})
				 }else{
					 this.$toast.fail('创建订单失败');
				 }
			},
			backproduct(){
				//this.$router.push({name:'product',query:{id:this.id}});
			   this.$router.back();
			},
			getData(){
				var alljia_price=0;
				var alljian_price=0;
				var allprice=0;
				//this.id = this.$route.query.id;//单个专栏id
			// console.log(this.$route.query);
			this.randcode=this.$route.query.randcode;
            this.strlist=decodeURIComponent(this.$route.query.shopinfo);
			// console.log(this.strlist);
            this.list=JSON.parse(this.strlist);
			this.randcode=this.$route.query.randcode;
            for(let item of this.list){
                alljia_price+=parseFloat(item['price'])*100;
            }
			if(this.jian_pricearr.length>0){
				let jianpricearr=JSON.parse(JSON.stringify(this.jian_pricearr));
				let r=trimSpace(jianpricearr)
			    for(let i of r){
                   alljian_price+=parseFloat(i)*100;
                }
			}else{
				   alljian_price=0;
			}
			this.allprice=(alljia_price-alljian_price)/100;
            if(this.allprice>0){
			let pricearr = this.allprice.toString().split('.');
			this.pricearr[0] = pricearr[0]+'.';
			this.pricearr[1] = pricearr[1]==undefined?'00':pricearr[1];
			}else if(this.allprice==0){
            this.pricearr[0] = 0+'.';
			this.pricearr[1] = '00';
			}
			},
			couponShow(index){
                this.$refs['coupon'+index].showList=true;
			}
		},
		async created(){
			this.getData();
		}
		}
</script>

<style lang="scss" scoped>
	.orderpage{
	   height: 100vh;
	   background-color: #eee;
	   overflow: scroll;
	.fixorder{
	      position: fixed;
	      right: 0;
	      bottom: 0;
	      left: 0;
	      height: 50px;
	      background-color: #fafafa;
		  line-height: 50px;
	   }
	   .van-card{
	   	background-color: white;
	    }
	}
</style>
